package WordCount

import org.apache.flink.streaming.api.scala._

/**
 * 流处理的WordCount
 */
object WordCountStream {
  def main(args: Array[String]): Unit = {
    //流处理的执行环境
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    //监听端口,socket文本流
    val inputDataStream = env.socketTextStream("192.168.23.69", 7777)
    //数据转换处理
    val resultDataStream = inputDataStream.flatMap(_.split(" "))
      .filter(_.nonEmpty)
      .map((_, 1))
      .keyBy(0)
      .sum(1)
    resultDataStream.print()

    //启动程序
    env.execute("wordcount")
  }
}
